# -*- coding: utf-8 -*-
"""
summary:
    此类是实现在Template里面方便使用 Filter 来调用一些常用的控件，并自已获取信息，不用主Views传数据
    避免重视在Views里面反复的读信息传到Template里面
author:
    Jason Lee<huacnlee@gmail.com>
"""
from django.template import Library,defaultfilters
from settings import *
from utils import helper

register = Library()

__TEMPLATE_ROOT = "components/"
__FILTER_NAME_PREFIX = "componsent_"

def user_bar(current_profile=None):
    """
    summary:
        用户栏
    params:
        current_profile    {obj}    用户Profile信息,None未登陆
    """
    _template_dir = "%suserbar/" % __TEMPLATE_ROOT

    if current_profile:
        _template = "%slogined.html" % _template_dir
    else:
        _template = "%sun_logined.html" % _template_dir

    _data = {
            "current_profile" : current_profile
            }

    return defaultfilters.safe(helper.view.out_html(_template,_data))

# regist filter
register.filter('%suser_bar' % __FILTER_NAME_PREFIX, user_bar)